import Mock from 'mockjs'
const Random = Mock.Random

export const getList = () => {
  let result = []

  // id, pid, name, shortName, parentName, code, level, remark,
  for (let i = 0; i < 3; i++) {
    const id = Random.string(32)
    const name = `Company-${i}`
    result.push({
      id,
      name,
      shortName: `C-${i}`,
      level: `00000${i}`
    })
    for (let j = 0; j < 4; j++) {
      const id2 = Random.string(32)
      const name2 = `Dept-${i}-${j}`
      result.push({
        id: id2,
        name: name2,
        shortName: `D-${i}-${j}`,
        level: `00000${i}00000${j}`,
        pid: id,
        parentName: name
      })

      for (let k = 0; k < 2; k++) {
        result.push({
          id: Random.string(32),
          name: `Office-${i}-${j}--${k}`,
          shortName: `O-${i}-${j}-${k}`,
          level: `00000${i}00000${j}00000${k}`,
          pid: id2,
          parentName: name2
        })
      }
    }
  }

  return {
    data: result
  }
}

export const getTree = () => {
  return []
}

export const saveOrg = ({ body }) => {
  body = JSON.parse(body)
  return {
    data: body.id ? body : Object.assign({}, body, { id: Random.string(32) })
  }
}
